package com.yuyuan.user.utils;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.yuyuan.user.domain.po.User;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Author: kestrel
 * @Version:1.0
 * @Date: 2024/5/27
 */
@Component
public class TokenGenerator {
    public String getToken(User user, String sessionKey) {
        return JWT.create()
                .withKeyId(user.getId().toString())
                .withIssuer("www.ikertimes.com")
                .withIssuedAt(new Date())
                .withJWTId("jwt.ikertimes.com")
                .withAudience(user.getId().toString())
                .withClaim("session_key", sessionKey)
                .sign(Algorithm.HMAC256(user.getPassword()));
    }

}
